//引入一个路由
import VueRouter from "vue-router"

import Vue from "vue"
//引入组件
import Main from "../view/Main"
import Dept from '../view/Dept'
import Home from '../view/Home'
import Emp from '../view/Emp'
import Login from '../view/Login'

Vue.use(VueRouter)

// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default new VueRouter({
    routes: [
        {
            path: '/main',
            name: 'Main',
            component: Main,
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: Home,
                },
                {
                    path: '/dept',
                    name: 'dept',
                    component: Dept
                },
                {
                    path: '/emp',
                    name: 'emp',
                    component: Emp
                },
            ],
        },
        //登录
        {
            path: '/login',
            name: 'login',
            component: Login,
        },
        //重定向，立马访问到首页
        {
            path: '*',
            redirect: '/login'
        },
    ]
})